package com.woniuxy.educationplatform.mapper;

import com.woniuxy.educationplatform.bean.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.context.annotation.Bean;

import java.util.List;

@Mapper
public interface StudentMapper {


    /**
     *
     * @param studentBean
     * @return
     */
    @Update("<script>" +
            "update student_info" +
            "<set>" +
            "<if test='s.stuName != null'>" +
            " stu_name = #{s.stuName}," +
            "</if>" +
            "<if test='s.stuLoginName != null'>" +
            " stu_login_name = #{s.stuLoginName}," +
            "</if>" +
            "<if test='s.password != null'>" +
            " password = #{s.password}," +
            "</if>" +
            "<if test='s.telephone != null'>" +
            " telephone = #{s.telephone}," +
            "</if>" +
            "<if test='s.education != null'>" +
            " education = #{s.education}," +
            "</if>" +
            "<if test='s.statusBean != null'>" +
            " fk_status_id = #{s.statusBean.id}," +
            "</if>" +
            "<if test='s.school != null'>" +
            " fk_school_id = #{s.school.id}," +
            "</if>" +
            "</set>" +
            "where id = #{s.id}" +
            "</script>")
    int updateStudentBean(@Param("s") StudentBean studentBean);


    /**
     * 删除学生
     * @param id
     * @return
     */
    @Delete("delete from student_info where id = #{id}")
    int deleteStudentBean(@Param("id")Long id);

/*    @Results({
           *//* @Result(id=true,property = "id",column = "id",javaType = Long.class),
            @Result(property = "stuName",column = "stu_name",javaType = String.class),
            @Result(property = "stuLoginName",column = "stu_login_name",javaType = String.class),
            @Result(property = "gender",column = "gender",javaType = String.class),
            @Result(property = "password",column = "password",javaType = String.class),
            @Result(property = "telephone",column = "telephone",javaType = String.class),
            @Result(property = "birthday",column = "birthday",javaType = String.class),*//*
            @Result(property = "addresses",column = "fk_address_id",javaType = OrderAddress.class,one =
            @One(select = "com.woniuxy.springbootstudy.mapper.DeptMapper.getOneById",fetchType = FetchType.LAZY)),
            @Result(property = "roleBean",column = "fk_role_id",javaType = RoleBean.class,one =
            @One(select = "com.woniuxy.springbootstudy.mapper.RoleMapper.getOneById",fetchType = FetchType.LAZY))
    })
    @Select("select * from student_info where id = #{id}")
    StudentBean getOneById(Long id);*/


//    List<StudentBean> findAllByParams(@Param("s") StudentBean studentBean);
    //查询全部学生
    List<StudentBean> findAllClassByParams(@Param("s") StudentBean studentBean);

    //根据学校姓名查里面的学生
    List<StudentBean> findStudent(@Param("s") StudentBean studentBean);

    //查询所有学生的观看记录

    @Select({
            "<script>"+
            "select * from student_info "+
            "<where> 1=1"+
            "<if test =\" stuName != null and stuName != '' \"> AND stu_name = #{stuName} </if>"+
            "</where>"+
            "</script>"
    })
    @Results({
            @Result(id=true,column="id",property="id"),
            @Result(column="id",property="videoes",many=@Many(select="findOneStudentAllRecording",fetchType= FetchType.LAZY))
    })
    List<StudentBean> findAllStudentRecording(StudentBean studentBean);


    @Results({
            //甚至连主键都可以省略
            @Result(id = true, property = "id", column = "id", javaType = Integer.class),
            @Result(property = "videoId", column = "video_id", javaType = VideoBean.class, one =
            @One(select = "findVideById", fetchType = FetchType.LAZY))
    })
    @Select("select * from stu_video where stu_id = #{stuId}")
    List<StuVideosBean> findOneStudentAllRecording();

    @Select("select * from video where id = #{stuId}")
    VideoBean findVideById(Integer id);

    //通过学号手机号教育背景是否为线下学员注册时间查询所有学生
    @Select({
            "<script>"+
                    "select * from student_info "+
                    "<where> 1=1"+
                    "<if test =\" stuName != null and stuName != '' \"> AND stu_name = #{stuName} </if>"+
                    "<if test =\" telephone != null and telephone != '' \"> AND telephone = #{telephone} </if>"+
                    "<if test =\" gender != null and gender != '' \"> AND gender = #{gender} </if>"+
                    "<if test =\" offline != null and offline != '' \"> AND offline = #{offline} </if>"+
                    "<if test =\" signInTime != null and signInTime != '' \"> AND sign_in_time = #{signInTime} </if>"+
                    "</where>"+
                    "</script>"
    })
    List<StudentBean> findAllStudentDetails(StudentBean studentBean);


    //根据学生id查询某一个学生
    @Select("select * from student_info where id = #{id}")
    StudentBean findStudentById(int id);

    //根据学校ID查里面的学生
    List<StudentBean> findStudentBySchoolID(Integer schoolID);

    //通过姓名 手机号 是否为线下学员 所属校区名字 查询所有学生
/*    @Select({
            "<script>"+
                    "select * from student_info "+
                    "<where> 1=1"+
                    "<if test =\" stuName != null and stuName != '' \"> AND stu_name = #{stuName} </if>"+
                    "<if test =\" telephone != null and telephone != '' \"> AND telephone = #{telephone} </if>"+
                    "<if test =\" offline != null and offline != '' \"> AND offline = #{offline} </if>"+
                    "<if test =\" signInTime != null and signInTime != '' \"> AND sign_in_time = #{signInTime} </if>"+
                    "</where>"+
                    "</script>"
    })
    List<StudentBean> findAllStudentDetailsAndSchool(StudentBean studentBean);*/

    /**
     * 分页查询
     * @param studentBean 含有参数的studentBean
     * @return List集合
     */
    List<StudentBean> findAllByParams(@Param("s") StudentBean studentBean);



   // List<TestBean> findAllTest();

}
